<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Bezdelnick
 * Date: 30.04.13
 * Time: 13:51
 * To change this template use File | Settings | File Templates.
 */
$PATH = Config::getInstance()->getBasePath();
require_once("$PATH/dao/AbstractDao.php");
require_once("$PATH/controller/QuestionController.php");

class QuestionDao extends AbstractDao
{
    function __construct()
    {
        $this->controller = new QuestionController();
    }

    public function loadByVoteId($voteId)
    {
        // Create query
        $query =
            "SELECT * FROM questions ".
                "INNER JOIN rel_votes_questions ON ( ".
                "rel_votes_questions.question_id=questions.id AND ".
                "rel_votes_questions.vote_id=" . $voteId . ")";

        // Load data from database
        $result = mysql_query(
            $query, Config::getInstance()->getDbConnection()
        );

        // Build object's array
        $instances = array();
        while ($row = mysql_fetch_array($result)) {
            $instance = PatternUtil::getInstance()->getObjectFromArray(
                $this->controller, $row);
            array_push($instances, $instance);

            /*var_dump($instance);
           echo "<br/>";*/
        }
        return $instances;
    }
}